<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>载入一新字体</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.imageline.html">imageline</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.imagepalettecopy.html">imagepalettecopy</a></div>
 <div class="up"><a href="ref.image.html">GD and Image 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.imageloadfont" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imageloadfont</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">imageloadfont</span> &mdash; <span class="dc-title">载入一新字体</span></p>

 </div>
 <div class="refsect1 unknown-unknown-noteu" id="refsect1-function.imageloadfont-unknown-unknown-noteu">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">int</span> <span class="methodname"><strong>imageloadfont</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$file</code></span>
   )</div>

  <p class="para rdfs-comment">
   <span class="function"><strong>imageloadfont()</strong></span>
   加载一个用户定义的位图字体并返回该字体的标识符（其值总是大于
   5，因此不会和内置字体冲突）。
   在产生错误的情况下，该函数返回 <strong><code>FALSE</code></strong> 。
  </p>
  <p class="para">
   字体文件格式目前是二进制的且和平台有关。这意味着应该用和你运行
   PHP 的机器相同类型 CPU 的机器生成字体。
  </p>
  <p class="para">
   <table class="doctable table">
    <caption><strong>字体文件格式</strong></caption>
    
     <thead>
      <tr>
       <th>字节位置</th>
       <th>C 数据类型</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>byte 0-3</td>
       <td>int</td>
       <td>字体中的字符数目</td>
      </tr>

      <tr>
       <td>byte 4-7</td>
       <td>int</td>
       <td>字体中第一个字符的值（通常是 32 代表空格）</td>
      </tr>

      <tr>
       <td>byte 8-11</td>
       <td>int</td>
       <td>每个字符宽度的像素值</td>
      </tr>

      <tr>
       <td>byte 12-15</td>
       <td>int</td>
       <td>每个字符高度的像素值</td>
      </tr>

      <tr>
       <td>byte 16-</td>
       <td>char</td>
       <td>字符数据的数组，每字符中每像素一字节，一共 (nchars*width*height) 字节。</td>
      </tr>

     </tbody>
    
   </table>

  </p>
  <p class="para">
   <div class="example" id="example-3179">
    <p><strong>Example #1 使用 imageloadfont</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />header</span><span style="color: #007700">(</span><span style="color: #DD0000">"Content-type:&nbsp;image/png"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$im&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecreatetruecolor</span><span style="color: #007700">(</span><span style="color: #0000BB">50</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">20</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$black&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecolorallocate</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$white&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecolorallocate</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">255</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">255</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">255</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">imagefilledrectangle</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">49</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">19</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$white</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$font&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imageloadfont</span><span style="color: #007700">(</span><span style="color: #DD0000">"04b.gdf"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">imagestring</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$font</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Hello"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$black</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">imagepng</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   参见 <span class="function"><a href="function.imagefontwidth.html" class="function">imagefontwidth()</a></span> 和
   <span class="function"><a href="function.imagefontheight.html" class="function">imagefontheight()</a></span>。
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.imageline.html">imageline</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.imagepalettecopy.html">imagepalettecopy</a></div>
 <div class="up"><a href="ref.image.html">GD and Image 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
